package com.compass.mobile.presenters

import UserInfoManager
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.leanback.widget.Presenter
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.compass.mobile.R
import com.compass.mobile.framework.ext.gone
import com.compass.mobile.framework.ext.visible
import com.compass.mobile.framework.utils.DateUtils
import com.compass.mobile.models.Inspection
import com.compass.mobile.ui.adapter.InspectionItemAdapter

/**
 * Description：
 * Date:2024/6/20 21:51
 */
class MyInspectionPresenter : Presenter() {

    override fun onCreateViewHolder(viewGroup: ViewGroup): ViewHolder {
        val view = LayoutInflater.from(viewGroup.context)
            .inflate(R.layout.layout_inspection_order_item, viewGroup, false)
        return ViewHolder(view)
    }

    override fun onBindViewHolder(viewHolder: Presenter.ViewHolder, item: Any) {
        if (item is Inspection) {
            val vh = viewHolder as ViewHolder
            vh.inspectionItemAdapter = InspectionItemAdapter()
            vh.tvStatus.text = item.statusName
            vh.tvData.text =
                "开具日期 ${DateUtils.conversionTime(item.createTime, DateUtils.FORMAT_TWO)}"
            vh.rcy_item.apply {
                layoutManager = LinearLayoutManager(context)
                adapter = vh.inspectionItemAdapter
            }
            vh.inspectionItemAdapter?.setData(item.projectRespVOS)
            when (item.status) {
                "0"->{
                    //未支付
                    vh.tvPay.visible()
                }
                else->{
                    vh.tvPay.gone()
                }
            }

        }
    }

    override fun onUnbindViewHolder(viewHolder: Presenter.ViewHolder) {

    }


    class ViewHolder(view: View) : Presenter.ViewHolder(view) {
        var rcy_item: RecyclerView = view.findViewById(R.id.rcy_item)
        var tvData: TextView = view.findViewById(R.id.tvData)
        var tvStatus: TextView = view.findViewById(R.id.tvStatus)
        var tvPay: TextView = view.findViewById(R.id.tvPay)
        var inspectionItemAdapter: InspectionItemAdapter? = null
    }
}